﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using EntLibContrib.Query;

namespace EntLibContrib.Mapping.QuickStart.DomainObjects
{
	[Mapper(Name = "Audit Mapper")]
	public class Audit
	{
		#region Fields
		private Guid primaryId;
		private Guid secondaryId;
		private Guid createdIdentityId;
		private Identity createdIdentity;
		private DateTime createdDate;
		private Guid updatedIdentityId;
		private Identity updatedIdentity;
		private DateTime updatedDate;
		private Guid deletedIdentityId;
		private Identity deletedIdentity;
		private DateTime deletedDate;
		#endregion

		#region Properties
		[Map()]
		public Guid PrimaryId
		{
			get { return primaryId; }
			set { primaryId = value; }
		}

		[Map()]
		public Guid SecondaryId
		{
			get { return secondaryId; }
			set { secondaryId = value; }
		}

		[Map()]
		public Guid CreatedIdentityId
		{
			get { return createdIdentityId; }
			set { createdIdentityId = value; }
		}

		public Identity CreatedIdentity
		{
			get
			{
				if (createdIdentity == null)
				{
					if (createdIdentityId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", createdIdentityId);
						createdIdentity = MapperFactory.CreateMapper("Identity Mapper").ToDomainObject<Identity>(QueryFactory.CreateQuery("Read Identity By Id").ExecuteForRead(parameters));
					}
				}

				return createdIdentity;
			}
		}

		[Map()]
		public DateTime CreatedDate
		{
			get { return createdDate; }
			set { createdDate = value; }
		}

		[Map()]
		public Guid UpdatedIdentityId
		{
			get { return updatedIdentityId; }
			set { updatedIdentityId = value; }
		}

		public Identity UpdatedIdentity
		{
			get
			{
				if (updatedIdentity == null)
				{
					if (updatedIdentityId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", updatedIdentityId);
						updatedIdentity = MapperFactory.CreateMapper("Identity Mapper").ToDomainObject<Identity>(QueryFactory.CreateQuery("Read Identity By Id").ExecuteForRead(parameters));
					}
				}

				return updatedIdentity;
			}
		}

		[Map()]
		public DateTime UpdatedDate
		{
			get { return updatedDate; }
			set { updatedDate = value; }
		}

		[Map()]
		public Guid DeletedIdentityId
		{
			get { return deletedIdentityId; }
			set { deletedIdentityId = value; }
		}

		public Identity DeletedIdentity
		{
			get
			{
				if (deletedIdentity == null)
				{
					if (deletedIdentityId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", deletedIdentityId);
						deletedIdentity = MapperFactory.CreateMapper("Identity Mapper").ToDomainObject<Identity>(QueryFactory.CreateQuery("Read Identity By Id").ExecuteForRead(parameters));
					}
				}

				return deletedIdentity;
			}
		}

		[Map()]
		public DateTime DeletedDate
		{
			get { return deletedDate; }
			set { deletedDate = value; }
		}
		#endregion

		#region Construction
		public Audit()
		{ }
		#endregion
	}
}
